<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>账号绑定</title>
    <base href="<?php echo base_url(); ?>"/>
    <link href="style/base.css" rel="stylesheet" type="text/css"/>
    <link href="style/common.css" rel="stylesheet" type="text/css"/>
    <link href="style/houtai.css" rel="stylesheet" type="text/css"/>
    <link href="style/my.css" rel="stylesheet" type="text/css"/>
    <!-- <link href="uploadify/css/default.css" rel="stylesheet" type="text/css" /> -->
    <link href="uploadify/css/uploadify.css" rel="stylesheet" type="text/css"/>
    <script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
    <script src="js/organictabs.jquery.js"></script>
    <script type="text/javascript" src="js/Common.js"></script>
    <script type="text/javascript" src="js/Validation.js"></script>
    <script type="text/javascript" src="jscript/WdatePicker.js"></script>
    <script type="text/javascript" src="js/jquery.form.js"></script>
    <script type="text/javascript" src="js/jquery.blockUI.js"></script>
    <script type="text/javascript" src="uploadify/scripts/swfobject.js"></script>
    <script type="text/javascript" src="uploadify/scripts/jquery.uploadify.v2.1.0.min.js"></script>
    <script type="text/javascript">
        $(function () {
            loadWeibo();
            bind();
        });
        function bind() {
            $("#ulWeibo li a").show().next("span").remove();
            $("#ulWeibo li a[status='0']").unbind("click").bind("click", function () {
                $("#ulWeibo li a").show().next("span").remove();
                $(this).hide();
                var value = $(this).attr("value");
                $(this).after("<span style='font-size:12px'>绑定：<input id='txtBind' type='text' style='width:120px;height:26px;' /><img id='btnSave' src='images/bc_inp.jpg' class='link' style='width:66px;height:24px;vertical-align:middle' /><img id='btnCancel' src='images/fq_inp.jpg' style='width:40px;height:24px;vertical-align:middle' class='link'/></span>")
                $("#btnSave").bind("click", function () {
                    save(value)
                });
                $("#btnCancel").bind("click", cancel);
            });
            $("#ulWeibo li a[status='1']").unbind("click").bind("click", function () {
                $("#ulWeibo li a").show().next("span").remove();
                if (confirm('确定要解除绑定吗？') == false)
                    return;
                var value = $(this).attr("value");
                delWeibo(value);
            });
        }
        function delWeibo(value) {
            var params = {
                wid: value
            };
            $.ajax({
                type: "post",
                url: "index.php/manage/delWeibo",
                dataType: "json",
                data: params,
                async: false,
                success: function (data) {
                    alert("解除绑定成功");
                    loadWeibo();
                    bind();
                }
            });
        }
        function cancel() {
            $(this).parents("span").hide().prev("a").show();
            $(this).remove();
        }
        function save(value) {
            if (check() == false)
                return;
            var url = $.trim($("#txtBind").val());
            var params = {
                wid: value,
                url: url
            };
            $.ajax({
                type: "post",
                url: "index.php/manage/saveWeibo",
                dataType: "json",
                data: params,
                success: function (data) {
                    alert("绑定成功");
                    loadWeibo();
                    bind();
                }
            });
        }
        function loadWeibo() {
            $.ajax({
                type: "post",
                url: "index.php/manage/loadWeibo",
                dataType: "json",
                async: false,
                success: function (data) {
                    $("#ulWeibo li a").each(function () {
                        var v = "/" + $(this).attr("value") + "/";
                        if (data.wid.indexOf(v) != -1) {
                            $(this).text("[解除绑定]")
                            $(this).prev("br").prev("img").attr("src", "images/xlwb_c.jpg");
                            $(this).attr("status", "1");
                        } else {
                            $(this).text("[立即绑定]");
                            $(this).prev("br").prev("img").attr("src", "images/xlwb_h.jpg");
                            $(this).attr("status", 0);
                        }
                    });
                }
            });
        }
        function check() {
            var name = $.trim($("#txtBind").val());
            if (IsEmpty(name)) {
                //SetError("txtBind","必填");
                alert("请输入地址");
                return false;
            }
            var len = name.length;
            if (len <= 0 || len > 100) {
                //SetError("txtBind","最多100字符");
                alert("最多100字符");
                return false;
            }
            ClearError("txtBind");
            return true;
        }
    </script>
<body>
<!-- head S-->
<?php
include 'header.php';
?>
<!-- head E-->

<div class="houtai_content mt_10 clearfix">
    <!-- 侧栏 开始 -->
    <?php
    include 'member_left.php';
    ?>
    <!-- 侧栏 结束 -->
    <div class="houtai_main">
        <div class="houtai_index">
            <div class="houtai_main_tit">用户中心&mdash;同步绑定</div>
            <form id="formCard">

                <!-- 同步绑定 开始 -->

                <div class="tongbu">
                    <ul id="ulWeibo">
                        <li style="width:300px;height:170px"><img src="images/xlwb_h.jpg" width="109" height="109"/>
                            <br/> <a href="javascript:void(0)" value="1">[立即绑定]</a></li>
                        <li style="width:300px;height:170px"><img src="images/xlwb_h.jpg" width="109" height="109"/>
                            <br/> <a href="javascript:void(0)" value="2">[立即绑定]</a></li>
                        <li style="width:300px;height:170px"><img src="images/xlwb_h.jpg" width="109" height="109"/>
                            <br/> <a href="javascript:void(0)" value="3">[立即绑定]</a></li>


                        <li style="width:300px;height:170px"><img src="images/xlwb_c.jpg" width="109" height="109"/>
                            <br/> <a href="javascript:void(0)" value="4">[解除绑定]</a></li>
                        <li style="width:300px;height:170px"><img src="images/xlwb_c.jpg" width="109" height="109"/>
                            <br/> <a href="javascript:void(0)" value="5">[解除绑定]</a></li>
                        <li style="width:300px;height:170px"><img src="images/xlwb_c.jpg" width="109" height="109"/>
                            <br/> <a href="javascript:void(0)" value="6">[解除绑定]</a></li>
                    </ul>
                </div>
                <!-- 同步绑定 结束 -->


            </form>
            </div>
        </div>
    </div>

            <!-- 页脚 开始 -->
            <?php include 'footer.php'; ?>
            <!-- 页脚 结束 -->
</body>
</html>
